import { configureStore } from '@reduxjs/toolkit'
import undoable, { excludeAction, StateWithHistory } from 'redux-undo'
import componentsReducer, { ComponentStateType } from './componentsReducer'
import pageInfoReducer, { PageInfoType } from './pageInfoReducer'
import userReducer, { UserSliceType } from './userReducer'

export default configureStore({
  reducer: {
    // 分模块的
    user: userReducer,

    // 组件列表
    // 没有 undo
    // components: componentsReducer,
    // 使用 undo
    components: undoable(componentsReducer, {
      limit: 20,
      filter: excludeAction([
        'components/resetComponents',
        'components/changeSelectedId',
        'components/selectNextComponent',
        'components/selectPrevComponent',
      ]),
    }),
    // 页面信息
    pageInfo: pageInfoReducer,
    // 问卷信息
  },
})

export type StateType = {
  user: UserSliceType
  components: StateWithHistory<ComponentStateType>
  pageInfo: PageInfoType
}
